<?php

setlocale(LC_ALL, "ru_RU.UTF-8");
mb_internal_encoding("UTF-8");

require_once ("./config/setup.php");
require_once ("./libs/db.class.php");
require_once ("./libs/utils.inc.php");
$sm = new SSmarty();
$db = new DB();

$curRealDir = mb_substr($_SERVER["SCRIPT_FILENAME"], 0, mb_strrpos($_SERVER["SCRIPT_FILENAME"], "/"));
$curRealDir = mb_substr($curRealDir, 0, mb_strrpos($curRealDir, "/"));
$curSiteDir = "http://" . $_SERVER["SERVER_NAME"] . mb_substr($_SERVER["PHP_SELF"], 0, mb_strrpos($_SERVER["PHP_SELF"], "/"));
$curPage = mb_substr($_SERVER["SCRIPT_NAME"], mb_strrpos($_SERVER["SCRIPT_NAME"], "/") + 1);

$sm->assign("curSiteDir", $curSiteDir);
$sm->assign("curPage", $curPage);

if (isset($_POST["optionsChangeEnter"])) {
    $_POST = escapeRecursive($_POST);

    $sets = array();
    foreach ($_POST as $key => $value) {
        if(preg_match("'^[\d]+$'iusx", $value)) {
            $sets[] = $key." = \"".$value."\"";
        }
    }

    $db->dbq("
                Update
                    options
                Set
                    ".  implode(",", $sets)."
            ");

    $sm->assign("redirectPage", $curPage);
    $sm->display("reset.html");
    exit(0);
}

$db->dbq("
            Select
                *
            From
                options
        ");
$options = $db->assoc();
$sm->assign("options", $options);

$sm->assign("design", $sm->template_dir);
$sm->display("options.html");
?>